package cn.th.service.impl;

import cn.th.entity.Gift;
import cn.th.entity.Item;
import cn.th.mapper.ItemMapper;
import cn.th.service.IItemService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 物品表（任务所需的东西，不限于实物） 服务实现类
 * </p>
 *
 * @author cn.th
 * @since 2024-03-30
 */
@Service
public class ItemServiceImpl extends ServiceImpl<ItemMapper, Item> implements IItemService {

    @Autowired
    private IItemService itemService;

    @Override
    public Map<String, Object> queryItem(int page, int pageSize, String school, String name, String attribute) {
        LambdaQueryWrapper<Item> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(StringUtils.hasLength(school), Item::getSchool, school);
        wrapper.like(StringUtils.hasLength(name), Item::getName, name);
        wrapper.eq(StringUtils.hasLength(attribute), Item::getAttribute, attribute);

        Page<Item> page1 = new Page<>(page,pageSize);

        itemService.page(page1,wrapper);

        Map<String, Object> data = new HashMap<>();
        data.put("total",page1.getTotal());
        data.put("rows",page1.getRecords());

        return data;
    }
}
